package TUILayer;
import java.util.Scanner;
import ControlLayer.*;


/**
 * Write a description of class OrderUI here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class OrderUI
{
    // instance variables - replace the example below with your own
    private OrderCtr orderCtr;
    private dataLoader dl;

    /**
     * Constructor for objects of class OrderUI
     */
    public OrderUI()
    {
        // initialise instance variables
        orderCtr = new OrderCtr();
        dl = new dataLoader();
    }

    public void callDaNigga()
    {
        loadData();
        boolean exit = false;
        while (!exit)
        {
            int choice = writeOrderMenu();
            if(choice == 1)
            {
                createOrder();
            }
            else
            {
                    if (choice == 2)
                    { 
                        deleteOrder();
                    }
                    else
                    {
                        if (choice == 3)
                        {
                            findOrder();
                        }//end if
                        else
                        {
                            if (choice == 4)
                            {
                                listAllOrders();
                            }
                            else
                            {
                                writeEnd();
                                exit = true;
                            }//end else
                        }//end else
                    }// end else
            }//end else
        }//end while
    }//end start
    
    private int writeOrderMenu()
    {       
        // creates a keyboard object to read input
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** Order Menu ***");
        System.out.println(" (1) Create Order");
        System.out.println(" (2) Delete Order");
        System.out.println(" (3) Find Order");
        System.out.println(" (4) List All Orders");
        System.out.println(" (5) Close");
        System.out.print("\n Make your choice: ");
            
        int choice = keyboard.nextInt();
            
        return choice;
    }
    
    private String inputOrderId()
    {   
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type order ID: ");
        String orderId = keyboard.nextLine();
        
        return orderId;
    }
    
    private String inputProductId()
    {   
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type product ID: ");
        String productId = keyboard.nextLine();
        
        return productId;
    }
    
    private String inputCustomerId()
    {   
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type customer ID: ");
        String customerId = keyboard.nextLine();
        
        return customerId;
    }
    
    private String inputItemId()
    {   
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type item ID (or leave blank): ");
        String itemId = keyboard.nextLine();
        
        return itemId;
    }
    
    private String inputDeliveryTypeId()
    {   
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type delivery type ID (or leave blank): ");
        String deliveryTypeId = keyboard.nextLine();
        
        return deliveryTypeId;
    }
    
    private String inputPaymentTypeId()
    {   
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type payment type ID: ");
        String paymentTypeId = keyboard.nextLine();
        
        return paymentTypeId;
    }
    
    private String inputStaffId()
    {   
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type staff ID: ");
        String staffId = keyboard.nextLine();
        
        return staffId;
    }
    
    private void createOrder()
    {
        String _orderId = "";
        String _productId = "";
        String _itemId = "";
        String _customerId = "";
        String _paymentTypeId = "";
        String _deliveryTypeId = "";
        String _staffId = "";
        
        _orderId = inputOrderId();
        listAllProducts();
        _productId = inputProductId();
        listAllItems();
        _itemId = inputItemId();
        listAllCustomers();
        _customerId = inputCustomerId();
        listAllPaymentTypes();
        _paymentTypeId = inputPaymentTypeId();
        listAllDeliveryTypes();
        _deliveryTypeId = inputDeliveryTypeId();
        listAllStaffs();
        _staffId = inputStaffId();
        
        orderCtr.createOrder(_orderId, _productId, _itemId, _customerId, _deliveryTypeId, _paymentTypeId, _staffId);
    }
    
    private void deleteOrder()
    {
        String _orderId = "";
        
        listAllOrders();
        _orderId=inputOrderId();
        
        orderCtr.deleteOrder(_orderId);
    }
    
    private void findOrder()
    {
        String _orderId = "";
        _orderId = inputOrderId();
        System.out.println("\nOrder ID: " + orderCtr.findOrder(_orderId).getId() + "\nTotal Price: " + orderCtr.findOrder(_orderId).getTotalPrice());
    }
    
    private void listAllOrders()
    {
        orderCtr.listAllOrders();
    }
    
    private void listAllProducts()
    {
        orderCtr.listAllProducts();
    }
    
    private void listAllItems()
    {
        orderCtr.listAllItems();
    }
    
    private void listAllDeliveryTypes()
    {
        orderCtr.listAllDeliveryTypes();
    }
    
    private void listAllPaymentTypes()
    {
        orderCtr.listAllPaymentTypes();
    }
    
    private void listAllStaffs()
    {
        orderCtr.listAllStaffs();
    }
    
    private void listAllCustomers()
    {
        orderCtr.listAllCustomers();
    }
    
    private void subtotal()
    {
        System.out.println("Subtotal: " + orderCtr.calculateSubtotal());
    }
    
    private void checkOut()
    {
        System.out.println("Amount to pay: " + orderCtr.calculateTotal());
    }
    
    private void writeEnd()
    {
        System.out.println(" The System is shuting down ");
        System.exit(0);
    }
    
    private void loadData()
    {
        dl.loadData();
    }
}
